导航菜单
首页 >  p5 loadImage How to load an image from an internet URL  > How to upload an image from a URL?

How to upload an image from a URL?

Hi, I tried to upload an image from a URL, but from what I see it doesn’t work, only for images that I place locally.

The purpose of uploading images using URL is because in the JSON I receive it contains their URL.

Example:

let img;function preload () { img = 'https://digimon.shadowsmith.com/img/koromon.jpg';}function setup () {createCanvas (400, 400);image (img, 0, 0, width, height);}function draw () {background (220);}

This produces the error:

Uncaught TypeError: Failed to execute ‘drawImage’ on ‘CanvasRenderingContext2D’: The provided value is not of type ‘(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)’ (sketch: line 8)

The image command (img, 0, 0, width, height) should accept the URL parameter as well, not just local referencing.

相关推荐: